<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="keywords" content="">
		<meta name="description" content="">
		<meta name="viewport" content="width=device-width,initial-scale=1, maximum-scale=1.0, user-scalable=no" />	
		<title>美国易安友|注册激活</title>
		<link rel="stylesheet" href="/static/active/css/bootstrap.min.css" />
		<link rel="stylesheet" href="/static/active/css/public.css" />
		<link rel="stylesheet" href="/static/active/css/font-awesome.css" />
	</head>
	<body>
		<div class="container">
			<div class="activate-logo  text-center">
				<img src="/static/active/img/logo.jpg" alt="" />
				<p class="wordx">
					现在激活<br>
					车膜破损保障服务
				</p>
			</div>
			<form action="" method="post">
		        <div class="content-block">
		            <div>
		                <div class="col-xs-10 col-xs-offset-1 margin-bottom-22px">
		                	<span class="activate-input">
		                		<span>激活码</span>
		                		<input type="text" id="code_num"/>
		                	</span>		            		
		            	</div>	                
		            </div>
		            <div>
		                <div class="col-xs-10 col-xs-offset-1 margin-bottom-22px">
		                	<span class="activate-input">
		                		<span>投保人</span>
		                		<input type="text" id="username"/>
		                	</span>		            		
		            	</div>	                
		            </div>
		            <div>
		                <div class="col-xs-10 col-xs-offset-1 margin-bottom-22px">
		                	<span class="activate-input">
		                		<span>手机号</span>
		                		<input type="text" id='phone'/>
		                	</span>		            		
		            	</div>	                
		            </div>
		            <div>
		                <div class="col-xs-10 col-xs-offset-1 margin-bottom-22px">
		                	<span class="activate-input">
		                		<span>车<span style="color: #fff;">一</span>型</span>
		                		<input type="text" id="other_type" placeholder="如：马自达cx-5"/>
		                	</span>		            		
		            	</div>
		            </div>
		            <div>
		                <div class="col-xs-10 col-xs-offset-1 margin-bottom-22px">
		                	<span class="activate-input">
		                		<span>车牌号</span>
		                		<input type="text" id="car_no" placeholder="如：沪A00001"/>
		                	</span>		            		
		            	</div>	                
		            </div>
		        </div>
		    </form>
		    <div class="col-xs-9 col-xs-offset-2 padding-level-none">
		        <p>备注：</p>
		        <p class="activate-bz">1.激活码有效期为一个月，逾期将自动作废。</p>
		        <p class="activate-bz">2.激活后次日0点起生效，有效期为一年。</p>
		        <p class="activate-bz">3.请如实填写，输入错误的信息会导致无法赔付</p>
		    </div>
		    <div class="form-group text-center">
                <button class="btn btn-default activate-btn" type="submit">马上激活</button>
            </div>
		</div>
	</body>
	<script type="text/javascript" src="/static/active/js/jquery-2.2.3.min.js" ></script>
	<script type="text/javascript">
		$(document).ready(function (){
			// $('.selectbox').wrap('<div class="select_wrapper"></div>')
			// $('.selectbox').parent().prepend('<span id="cartype">'+ $(this).find(':selected').text() +'</span>');
			// $('.selectbox').css('display', 'none');					
			// $('.selectbox').parent().append('<ul class="select_inner"></ul>');
			// $('.selectbox').children().each(function(){
			// 	var opttext = $(this).text();
			// 	var optval = $(this).val();
			// 	$('.selectbox').parent().children('.select_inner').append('<li id="' + optval + '">' + opttext + '</li>');
			// });
		
			// $('.selectbox').parent().find('li').on('click', function (){
			// 	var cur = $(this).attr('id');
			// 	$('.selectbox').parent().children('span').text($(this).text());
			// 	$('.selectbox').children().removeAttr('selected');
			// 	$('.selectbox').children('[value="'+cur+'"]').attr('selected','selected');
								
			// 	/*console.log($('.selectbox').children('[value="'+cur+'"]').text());*/
			// });
			
			// $('.selectbox').parent().on('click', function (){
			// 	$(this).find('ul').slideToggle('fast');
			// });
	
			$.getJSON("{:U('active/get_car_type_list')}",function(data){
					var str = '<option>请选择</option>';
					for (var i = 0; i < data.length; i++) {
						str += '<option>'+data[i]+'</option>';
					};
					// console.log(str)
					$('#cartype').html(str)

			});


			$('.activate-btn').click(function(){
				var data = {};
				data.code_num = $("#code_num").val();
				data.username = $("#username").val();
				data.phone = $("#phone").val();
				// data.type = $("#cartype option:selected").text();
				// data.type = $("#cartype").val();
				data.other_type = $("#other_type").val();
				data.car_no = $("#car_no").val();

				if (data.code_num.length<1) {
					alert('请输入激活码')
					return false;
				}

				if (data.username.length<1) {
					alert('请输入投保人姓名')
					return false;
				}

				reg =  /^1[3|4|5|8|7][0-9]\d{8}$/;
				if(!reg.test(data.phone)){
					alert('手机号码格式错误，请重新输入');
					return false;
				}

				if (data.other_type.length<1 ) {
					alert('请输入投保车型')
					return false;
				}

				if (data.car_no.length<1) {
					alert('请输入车牌号')
					return false;
				}
				
				$.post("{:U('active/save')}",data,function(data){
					if (data['code']===0) {
						alert(data.message)
						location.assign("/index.php?m=active&a=active_success");
					}else if (data['code']===-5) {
						url = window.location.origin+"{:U('User/login')}";
						window.location.href=url;
					}else{
						alert(data.message)
					}

				},'json');

				
				
			})

		});
	</script>
</html>
